local skel = fk.CreateSkill {
  name = "emo__yunzhuan",
}

Fk:loadTranslationTable{
  ["emo__yunzhuan"] = "运转",
  [":emo__yunzhuan"] = "当一名角色需要打出一张基本牌时，你可以令其判定，若为基本牌，其视为打出之，否则，你获得判定牌且此技能本轮失效。",

  ["#emo__yunzhuan-invoke"] = "运转：你可以令 %src 判定，若结果为基本牌，视为打出【%arg】",
  ["#emo__yunzhuan-ask"] = "运转：你可以令 %src 判定，若结果为基本牌，视为打出一张基本牌",
  ["#emo__yunzhuan-choice"] = "运转：选择其打出的基本牌牌名",
}

skel:addEffect(fk.AskForCardResponse, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skel.name) and not data.result then
      return Exppattern:Parse(data.pattern):matchExp(".|.|.|.|.|basic")
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local names = table.filter(Fk:getAllCardNames("b"), function (name)
      return Exppattern:Parse(data.pattern):matchExp(name) and not target:prohibitResponse(Fk:cloneCard(name))
    end)
    if #names == 0 then return false end
    local prompt = ""
    if #names == 1 then
      prompt = "#emo__yunzhuan-invoke:" .. target.id .. "::" .. names[1]
    else
      prompt = "#emo__yunzhuan-ask:" .. target.id
    end
    if room:askToSkillInvoke(player, {skill_name = skel.name, prompt = prompt}) then
      event:setCostData(self, {names = names, tos = {target} })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local judge = {
      who = target,
      reason = skel.name,
      pattern = ".|.|.|.|.|basic",
    }
    room:judge(judge)
    if judge:matchPattern() then
      local names = table.filter(event:getCostData(self).names, function (name)
        return not target:prohibitResponse(Fk:cloneCard(name))
      end)
      if #names == 0 then return end
      local name = room:askToChoice(player, {choices = names, skill_name = skel.name, prompt = "#emo__yunzhuan-choice" })
      local card = Fk:cloneCard(name)
      card.skillName = skel.name
      data.result = {
        card = card,
        from = target,
      }
    elseif player:isAlive() then
      room:invalidateSkill(player, skel.name, "-round")
      if room:getCardArea(judge.card) == Card.DiscardPile then
        room:obtainCard(player, judge.card, true, fk.ReasonJustMove, player, skel.name)
      end
    end
  end,
})

return skel
